package com.tangtang.core.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Created by Administrator on 2014/4/10.
 */
public class MustBetweenValidator implements ConstraintValidator<MustBetween, Integer> {

    MustBetween must;

    @Override
    public void initialize(MustBetween constraintAnnotation) {
        this.must = constraintAnnotation;
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (value == null) {
            return false;
        }
        if (value >= must.min() && value <= must.max()) {
            return true;
        }
        return false;
    }
}
